package org.spring.blog.dao;

import org.spring.blog.pojo.RefreshToken;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface RefreshTokenDao extends JpaRepository<RefreshToken, String>, JpaSpecificationExecutor<RefreshToken> {

    RefreshToken findOneByTokenKey(String _tokenKey);

    RefreshToken findOneByMobileTokenKey(String _tokenKey);

    @Modifying
    int deleteAllByUserID(String userID);

    @Modifying
    @Query(nativeQuery = true, value = "update sob_blog_system.tb_refresh_token set sob_blog_system.tb_refresh_token.token_key = '' where sob_blog_system.tb_refresh_token.token_key = ?")
    void deletePcTokenKey(String _tokenKey);

    @Modifying
    @Query(nativeQuery = true, value = "update sob_blog_system.tb_refresh_token set sob_blog_system.tb_refresh_token.mobile_token_key = '' where sob_blog_system.tb_refresh_token.mobile_token_key = ?")
    void deleteMobileToken(String _tokenKey);

    RefreshToken findOneByUserID(String _id);
}
